/*
 * Copyright 2006-2023 ahtelit.com, All Rights Reserved.
 */

package com.telit.firecommand.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.telit.common.core.exceptions.BizException;
import com.telit.firecommand.dao.CameraSetDao;
import com.telit.firecommand.entity.CameraSet;
import com.telit.firecommand.service.CameraSetService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * CameraSetServiceImpl
 *
 * @author yuezhuang
 * @since 2023-11-21
 */
@Transactional
@RequiredArgsConstructor
@Slf4j
@Service
public class CameraSetServiceImpl extends ServiceImpl<CameraSetDao, CameraSet> implements CameraSetService {


    @Override
    public void add(CameraSet dto) {
        int count = this.count(
                Wrappers.<CameraSet>lambdaQuery().eq(CameraSet::getCameraIndexCode, dto.getCameraIndexCode()));
        Assert.isTrue(count <= 0, () -> new BizException("请勿重复添加，请刷新页面重试！"));
        super.save(dto);
    }

    @Override
    public void edit(CameraSet dto) {
        super.updateById(dto);
    }

    @Override
    public CameraSet detail(String cameraIndexCode) {
        return this.getOne(Wrappers.<CameraSet>lambdaQuery().eq(CameraSet::getCameraIndexCode, cameraIndexCode), false);
    }

}
